#ifndef __main_H__
#define __main_H__ 1

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/eeprom.h>

typedef  volatile unsigned char uChar_v;
typedef  unsigned char uChar;
typedef  volatile unsigned int uInt_v;
typedef  unsigned int uInt;
typedef  unsigned char uint8;

/////
#define Receive_En PORTD &=~0x04
#define Tran_En PORTD|=0x04

#ifdef	F_CPU
	#undef F_CPU
#endif

#ifndef	F_CPU
	#define F_CPU (8000000)
#endif
#define Fos	F_CPU


uInt_v Frme_reg;
//uChar_v Temp,Temp1,AdJ_C,;
//uChar_v ;

//DMX512 üĴ
uChar_v Ser,ID_add,
		Stobe,
		Dmx_C,//10:small control;20:starand DMX-512 control
		self_mode_En,automode,//slave_en,
		SerData[9];
uInt_v SerCont,Add_Set,led_sleep,Stobe_temp,led_display=20002;

uChar_v RGB_DATA[3]={0,0,0},dim[3];
uChar_v Sence_temp[6];
//dim[3]=0xff,0xff,0xff;
/*
#define	PWM_R	RGB_DATA[0]
#define	PWM_G	RGB_DATA[1]
#define	PWM_B	RGB_DATA[2]
*/
uChar_v T1_temp;//T1_temp1;

uChar_v menu1=1,menu2,menu3,menu4,key_vol;//;//1 dmx address,2 automode,3,id dress
uInt_v keyreapt;
#define RED_C	 RGB_DATA[0]
#define GREEN_C	 RGB_DATA[1]
#define BLUE_C	 RGB_DATA[2]

uChar Bit_use1;
#define Stobe_sy_bit (Bit_use1&(1<<0))
#define Stobe_sy_d  (Bit_use1&=~(1<<0))
#define Stobe_sy_e  (Bit_use1|=(1<<0))

#define DMX_end     (Bit_use1&(1<<1))
#define DMX_end_d     (Bit_use1&=~(1<<1))
#define DMX_end_e     (Bit_use1|=(1<<1))

#define Stobe_Start   (Bit_use1&(1<<2))
#define Stobe_Start_d     (Bit_use1&=~(1<<2))
#define Stobe_Start_e     (Bit_use1|=(1<<2))

#define master_bit			  (Bit_use1&(1<<3))
#define master_bit_d     (Bit_use1&=~(1<<3))
#define master_bit_e     (Bit_use1|=(1<<3))

#define auto_bit			  (Bit_use1&(1<<4))
#define auto_bit_d     (Bit_use1&=~(1<<4))
#define auto_bit_e     (Bit_use1|=(1<<4))
//#define Display register
unsigned char LEDM_D[4];

uChar data_cal(uChar data1,uChar data2,uChar data3)
{
	uChar i;
union 
	{
	struct
		{
		unsigned char data1;
		unsigned char data2;
		}data_L1;
	unsigned long data_L2;
	}data_L;

	 data_L.data_L2=data1*data2;//+data1;
	 i=data_L.data_L1.data2;
	 data_L.data_L2=i*data3;//+i;
	 return data_L.data_L1.data2;
}
uChar data_2cal(uChar data1,uChar data2)
{
	uChar i;
union 
	{
	struct
		{
		unsigned char data1;
		unsigned char data2;
		}data_L1;
	unsigned long data_L2;
	}data_L;

	 data_L.data_L2=data1*data2+data1;
	 i=data_L.data_L1.data2;
	 return data_L.data_L1.data2;
}
//union
//{
	struct add_Bit_use
	{
	unsigned char Display_on: 1;	
	unsigned char init_cal_c: 1;
	}Bit2_1;
	//unsigned char Bit_use2;
//}Bit2_2;

//define eeprom address
#define add_Dmx_h		0x01
#define add_Dmx_l		0x02
#define add_automode	0x03
#define add_ID_add		0x04
#define add_menu1		0x05
#define add_Bit_use1		0x06
#define add_dim_0		0x07
#define add_dim_1		0x08
#define add_dim_2		0x09

#endif
